// Copyright (c) Appeon
// The following has been modified by Appeon under compliance with the Apache 2.0 license from the original work

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Data;
using JetBrains.Annotations;

namespace SnapObjects.Data
{
    /// <summary>
    ///     <para>
    ///         Represents the mapping between a .NET <see cref="Decimal" /> type and a database type.
    ///     </para>
    ///     <para>
    ///         This type is typically used by database providers (and other extensions). It is generally
    ///         not used in application code.
    ///     </para>
    /// </summary>
    public class DecimalTypeMapping : TypeMapping
    {
        private const string DecimalFormatConst = "{0:0.0###########################}";

        /// <summary>
        ///     Initializes a new instance of the <see cref="DecimalTypeMapping" /> class.
        /// </summary>
        /// <param name="dbTypeName"> The name of the database type. </param>
        /// <param name="dbType"> The <see cref="DbType" /> to be used. </param>
        public DecimalTypeMapping(
            [NotNull] string dbTypeName,
            [CanBeNull] DbType? dbType = null)
            : base(dbTypeName, typeof(decimal), dbType)
        {
        }

        /// <summary>
        ///     Creates a copy of this mapping.
        /// </summary>
        /// <param name="dbTypeName"> The name of the database type. </param>
        /// <param name="size"> The size of data the property is configured to store, or null if no size is configured. </param>
        /// <returns> The newly created mapping. </returns>
        public override TypeMapping Clone(string dbTypeName, int? size)
        {
            return new DecimalTypeMapping(dbTypeName, this.DbType);
        }

        /// <summary>
        ///     Gets the string format to be used to generate SQL literals of this type.
        /// </summary>
        protected override string SqlLiteralFormatString => DecimalFormatConst;
    }
}
